package com.jinbo.footmessageworker.order;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.jinbo.footmessageworker.BaseActivity;
import com.jinbo.footmessageworker.MyApplication;
import com.jinbo.footmessageworker.R;
import com.jinbo.footmessageworker.httpbean.OrderBean;
import com.jinbo.footmessageworker.httpbean.OrdersBean;
import com.jinbo.footmessageworker.httpretrofit.BusinessController;
import com.jinbo.footmessageworker.httpretrofit.HttpProtocolFactory;
import com.jinbo.footmessageworker.httpretrofit.Listener;
import com.jinbo.footmessageworker.utils.LocalPreferencesHelper;
import com.jinbo.footmessageworker.view.TitleBarView;

import java.util.List;

public class DealtOrderListActivity extends BaseActivity implements View.OnClickListener{
    private ListView listView;
    List<OrderBean> orders;
    DealtOrderListViewAdapter adapter;

    public static final int REQUEST_CONFIRM = 200;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dealt_order);
        TitleBarView titleBarView = (TitleBarView) findViewById(R.id.titleBar);
        titleBarView.setCenterTitle("已接订单");
        titleBarView.setLeftBackButtonIsVisibler(true);
        titleBarView.setListener(TitleBarView.TitleBarEnum.ll_leftBackImageLayout, this);
        listView = (ListView)findViewById(R.id.mainListView);//列表
        adapter=new DealtOrderListViewAdapter(this,orders);
        listView.setAdapter(adapter);
        updateData();
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_back_layout:
                finish();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_CONFIRM) {
                updateData();
            }
        }
    }

    void updateData() {
        String worker_id = MyApplication.local.getString(LocalPreferencesHelper.USER_ID);
        BusinessController.getInstance().dealtOrder(worker_id, new Listener<OrdersBean>() {
            @Override
            public void onStart(Object... params) {
                showProgressDialog("请稍后...");
                //mLoadView.setVisibility(View.VISIBLE);
                // mPullRefreshLayout.setRefreshing(true);
                //mLoadView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onComplete(OrdersBean result, Object... params) {
                dismissProgressDialog();
                //mPullRefreshLayout.setRefreshing(false);
                // mLoadView.setVisibility(View.GONE);
                //mCallBacks1.change(result.orders);
                // mCallBacks2.change(result.orders);
                adapter.setorders(result.orders);


            }

            @Override
            public void onFail(final String msg, Object... params) {
                // mLoadView.setVisibility(View.VISIBLE);
                dismissProgressDialog();
                //mLoadView.setVisibility(View.GONE);
                //mPullRefreshLayout.setRefreshing(false);
                if (TextUtils.isEmpty(msg)) {
                } else {
                    show(msg);
                }
            }
        });
    }
}
